<template>
  <div>
    <div>
      <ul>
        <li @click="btn('allContacts')">All-contacts</li>
        <li @click="btn('alice')">Alice</li>
        <li @click="btn('bob')">Bob</li>
      </ul>
    </div>
    <div>
      <button @click="random">随机显示</button>
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: ["allContacts", "alice", "bob"],
    };
  },
  methods: {
    btn(name) {
      this.$router.push({name}).catch(() => {});
    },
    random() {
      const num = Math.floor(Math.random() * 3);
      this.$router.push(this.arr[num]).catch(() => {});
    },
  },
};
</script>

<style scoped>
li .router-link-active {
  color: red;
}
</style>
